<template>
  <div class="nav-con">
    <el-menu
      :default-active="$route.fullPath"
      class="el-menu-vertical-demo"
      background-color="#0e2439"
      text-color="#fff"
      active-text-color="#3063ac"
      :router="true"
      :collapse="sidebar"
    >
      <el-submenu :index="item.path" v-for="item in routes" :key="item.path">
        <template slot="title">
          <i class="iconfont" :class="item.meta.icon"></i>
          <span>{{ item.meta.title }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            :index="item.path + '/' + i.path"
            v-for="i in item.children"
            :key="item.path + '/' + i.path"
          >
            {{ i.meta.title }}</el-menu-item
          >
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "MyNav",
  data() {
    return {
      routes: [],
    };
  },
  computed: {
    ...mapGetters(["sidebar"]),
  },
  mounted() {
    let routes = [];
    console.log(this.$router);
    this.$router.options.routes.forEach((item) => {
      if (item.meta) {
        routes.push(item);
      }
    });
    this.routes = routes;
  },
};
</script>

<style scoped lang="scss">
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
}
.nav-con {
  // width: 200px;
  overflow: hidden;
  .iconfont {
    padding-right: 5px;
    font-weight: bold;
    color: #fff;
  }
  .el-menu {
    border-right: none;
  }
}
</style>